import { $get, $put } from '@js/request'
import { ConditionSchema } from '@src/components/schema/condition'
import { PerformanceSchema } from '@src/components/schema/performanceSchema'

export async function getCaseListRequest (d: { condition: ConditionSchema[], page: number, limit: number }): Promise<{ list: PerformanceSchema[], total: number }> {
  const condition = [...d.condition, { k: 'status', o: '<>', v: '作废' }]
  const res = await $get('/api/commission/performance', {
    condition: JSON.stringify(condition),
    page: d.page,
    limit: d.limit
  })
  const list: PerformanceSchema[] = res.data.list
  list.forEach((li, i) => {
    li.orderno = i + 1 + (d.page - 1) * d.limit
  })
  return res.data
}

// 计算
export async function computeRequest (): Promise<void> {
  const res = await $put('/api/commission/case/compute')
  return res.data
}

// 作废请求
export async function setPerformanceUnable (id: string): Promise<void> {
  const res = await $put(`/api/commission/performance/${id}`, {
    status: '作废'
  })
  return res.data
}
